//
//  AlbumTableViewCell.m
//  DolphinMusic
//
//  Created by dllo on 15/3/27.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "AlbumTableViewCell.h"

@implementation AlbumTableViewCell

- (void)dealloc
{
    [_album release];
    [_coverImageView release];
    [_titleLabel release];
    [_playCountImageView release];
    [_playcountLabel release];
    [_sourceCountImageView release];
    [_sourceCountLabel release];
    [_renewLabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.coverImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.coverImageView];
        [_coverImageView release];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        [_titleLabel release];
        
        self.playCountImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.playCountImageView];
        [_playCountImageView release];
        
        self.playcountLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.playcountLabel];
        [_playcountLabel release];
        
        self.sourceCountImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.sourceCountImageView];
        [_sourceCountImageView release];
        
        self.sourceCountLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.sourceCountLabel];
        [_sourceCountLabel release];
        
        self.renewLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.renewLabel];
        [_renewLabel release];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat width = self.contentView.frame.size.width;
    CGFloat height = self.contentView.frame.size.height;
    CGFloat height1 = height - 14;
    
    self.coverImageView.frame = CGRectMake(10, 7, height1, height1);
    [self.coverImageView setImageWithURL:[NSURL URLWithString:[self.album.albumCoverUrl290 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
    
    self.titleLabel.frame = CGRectMake(height, 7, width - (height + 10), height1 / 3);
    self.titleLabel.text = self.album.title;
    self.titleLabel.font = [UIFont systemFontOfSize:16];
    
    
    self.playCountImageView.frame = CGRectMake(height, 7 + height1 / 3, 20, height1 / 3);
    self.playCountImageView.image = [UIImage imageNamed:@"playNumber.png"];
    self.playCountImageView.contentMode = UIViewContentModeLeft;
    self.playCountImageView.alpha = 0.7;
    
    self.playcountLabel.frame = CGRectMake(self.playCountImageView.frame.origin.x + self.playCountImageView.frame.size.width + 3 + 10, self.playCountImageView.frame.origin.y, 70, height1 / 3);
    self.playcountLabel.text = self.album.playCounts;
    self.playcountLabel.font = [UIFont systemFontOfSize:14];
    
    self.sourceCountImageView.frame = CGRectMake(self.playcountLabel.frame.origin.x + self.playcountLabel.frame.size.width , self.playcountLabel.frame.origin.y, 20, height1 / 3);
    self.sourceCountImageView.image = [UIImage imageNamed:@"sourceNumber.png"];
    self.sourceCountImageView.contentMode = UIViewContentModeScaleAspectFit;
    
    self.sourceCountLabel.frame = CGRectMake(self.sourceCountImageView.frame.origin.x + self.sourceCountImageView.frame.size.width + 10, self.sourceCountImageView.frame.origin.y, 70, height1 / 3);
    self.sourceCountLabel.font = [UIFont systemFontOfSize:14];
    self.sourceCountLabel.text = self.album.trackCounts;
    
    
    self.renewLabel.frame = CGRectMake(height, 7 + height1 * 2 / 3, width - (height1 - 10 - 70), height1 / 3);
    self.renewLabel.font = [UIFont systemFontOfSize:14];
    self.renewLabel.text = [NSString stringWithFormat:@"最近更新:  %@", self.album.lastTrackDate];
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
